package com.tensquare.gathering.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.tensquare.gathering.domain.Usergath;
import com.tensquare.gathering.service.IUsergathService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户关注活动Controller
 * 
 * @author hbxfwf
 * @date 2021-08-25
 */
@RestController
@RequestMapping("/usergath")
public class UsergathController extends BaseController
{
    @Autowired
    private IUsergathService usergathService;

    /**
     * 查询用户关注活动列表
     */
    @PreAuthorize(hasPermi = "gathering:usergath:list")
    @GetMapping("/list")
    public TableDataInfo list(Usergath usergath)
    {
        startPage();
        List<Usergath> list = usergathService.selectUsergathList(usergath);
        return getDataTable(list);
    }

    /**
     * 导出用户关注活动列表
     */
    @PreAuthorize(hasPermi = "gathering:usergath:export")
    @Log(title = "用户关注活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Usergath usergath) throws IOException
    {
        List<Usergath> list = usergathService.selectUsergathList(usergath);
        ExcelUtil<Usergath> util = new ExcelUtil<Usergath>(Usergath.class);
        util.exportExcel(response, list, "用户关注活动数据");
    }

    /**
     * 获取用户关注活动详细信息
     */
    @PreAuthorize(hasPermi = "gathering:usergath:query")
    @GetMapping(value = "/{userid}")
    public AjaxResult getInfo(@PathVariable("userid") String userid)
    {
        return AjaxResult.success(usergathService.selectUsergathByUserid(userid));
    }

    /**
     * 新增用户关注活动
     */
    @PreAuthorize(hasPermi = "gathering:usergath:add")
    @Log(title = "用户关注活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Usergath usergath)
    {
        return toAjax(usergathService.insertUsergath(usergath));
    }

    /**
     * 修改用户关注活动
     */
    @PreAuthorize(hasPermi = "gathering:usergath:edit")
    @Log(title = "用户关注活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Usergath usergath)
    {
        return toAjax(usergathService.updateUsergath(usergath));
    }

    /**
     * 删除用户关注活动
     */
    @PreAuthorize(hasPermi = "gathering:usergath:remove")
    @Log(title = "用户关注活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userids}")
    public AjaxResult remove(@PathVariable String[] userids)
    {
        return toAjax(usergathService.deleteUsergathByUserids(userids));
    }
}
